<?php
namespace app\admin\model;

use think\Model;

class Common extends Model
{
	
	/**
	 * 获取分页
	 */
	public function getpage($where,$order="id desc"){
		$lists = $this
			->where($where)
			->order($order)
			->paginate(10);
		return $lists;
	}

	/**
	 * 获取全部数据
	 */
	public function getall($where,$order="id desc"){
		$lists = $this
			->where($where)
			->order($order)
			->select()->toArray();
		return $lists;
	}

	/**
	 * 修改保存数据
	 */
	public function savedata($data){
		if(!empty($data)){
			if(!empty($data['id'])){
				$id = $this->update($data, ['id' => $data['id']]);
				if(!empty($id)){
					return [
						'status'=>1,
						'notice'=>'操作成功！',
					];
				} else {
					return [
						'status'=>2,
						'notice'=>'操作失败！',
					];
				}
			} else{
				$id = $this->save($data);
				if(!empty($id)){
					return [
						'status'=>1,
						'notice'=>'操作成功！',
					];
				} else {
					return [
						'status'=>2,
						'notice'=>'操作失败！',
					];
				}
			}
		} else {
			return [
				'status'=>2,
				'notice'=>'数据不能为空！',
			];
		}
	}
	
	/**
	 * 设置时间
	 */
	public function setCreateTimeAttr($value){
		return strtotime($value);
	}
}
